uikits.controller('ModalDemoCtrl', function($scope, $modal, $log) {
	$scope.items = [ 'item1', 'item2', 'item3' ];
	$scope.open = function(size) {
		var modalInstance = $modal.open({
			templateUrl : 'myModalContent.html', //模板ID，优先查找内存
			controller : 'ModalInstanceCtrl',
			size : size,
			resolve : { 
				items : function() {
					return $scope.items;  //传递给模态窗口页面的内容,如果需要传递一个objec对象，需要使用angular.copy()
				},
				msg : function() { 
					return angular.copy("这是消息"); 
				}
			}
		});
		
		modalInstance.opened.then(function(){//模态窗口打开之后执行的函数  
            $log.info('Modal is opened at: ' + new Date());
        });

		modalInstance.result.then(  //得到模态窗口返回结果后
			function(selectedItem) {
				$scope.selected = selectedItem;
			}, function(reason) {
				$log.info('Modal dismissed because: ' + reason);
			}
		);
	};
});


/**
  * 注意：$modalInstance有如下几个方法。
  * 
  * close(result)：关闭模态窗口并传递一个结果
  * dismiss(reason)：撤销模态方法并传递一个原因
  * result：一个契约，当模态窗口被关闭或撤销时传递
  * opened：一个契约，当模态窗口打开并且加载完内容时传递的变量
  */
uikits.controller('ModalInstanceCtrl', function($scope, $modalInstance, $log, items, msg) { //items为接收父窗口传递的内容
	$log.info('Message arrived: ' + msg);
	$scope.items = items;
	$scope.selected = {item : $scope.items[0]};

	$scope.ok = function() {
		$modalInstance.close($scope.selected.item);
	};

	$scope.cancel = function() {
		$modalInstance.dismiss('cancel');
	};
});
